package com.ruoyi.project.crm.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.crm.domain.CrmCustomer;
import com.ruoyi.project.crm.service.ICrmCustomerService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * crm端用户管理Controller
 * 
 * @author ruoyi
 * @date 2020-06-30
 */
@RestController
@RequestMapping("/capi/customer")
public class CrmCustomerController extends BaseController
{
    @Autowired
    private ICrmCustomerService crmCustomerService;

    /**
     * 查询crm端用户管理列表
     */
    @PreAuthorize("@ss.hasPermi('capi:customer:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmCustomer crmCustomer)
    {
        startPage();
        List<CrmCustomer> list = crmCustomerService.selectCrmCustomerList(crmCustomer);
        return getDataTable(list);
    }

    /**
     * 导出crm端用户管理列表
     */
    @PreAuthorize("@ss.hasPermi('capi:customer:export')")
    @Log(title = "crm端用户管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CrmCustomer crmCustomer)
    {
        List<CrmCustomer> list = crmCustomerService.selectCrmCustomerList(crmCustomer);
        ExcelUtil<CrmCustomer> util = new ExcelUtil<CrmCustomer>(CrmCustomer.class);
        return util.exportExcel(list, "customer");
    }

    /**
     * 获取crm端用户管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('capi:customer:query')")
    @GetMapping(value = "/{cid}")
    public AjaxResult getInfo(@PathVariable("cid") Long cid)
    {
        return AjaxResult.success(crmCustomerService.selectCrmCustomerById(cid));
    }

    /**
     * 新增crm端用户管理
     */
    @PreAuthorize("@ss.hasPermi('capi:customer:add')")
    @Log(title = "crm端用户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmCustomer crmCustomer)
    {
        return toAjax(crmCustomerService.insertCrmCustomer(crmCustomer));
    }

    /**
     * 修改crm端用户管理
     */
    @PreAuthorize("@ss.hasPermi('capi:customer:edit')")
    @Log(title = "crm端用户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmCustomer crmCustomer)
    {
        return toAjax(crmCustomerService.updateCrmCustomer(crmCustomer));
    }

    /**
     * 删除crm端用户管理
     */
    @PreAuthorize("@ss.hasPermi('capi:customer:remove')")
    @Log(title = "crm端用户管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cids}")
    public AjaxResult remove(@PathVariable Long[] cids)
    {
        return toAjax(crmCustomerService.deleteCrmCustomerByIds(cids));
    }
}
